#include "stm32f10x.h"                  // Device header
#include "Delay.h"
#include "OLED.h"
#include "Motor.h"
#include "IR.h"
#include "Time.h"

//调试
//#include "LED.h"


extern uint32_t Data;
int8_t Speed;		//定义速度变量
int ModeFlag;

int main(void)
{
	/*模块初始化*/
	OLED_Init();		//OLED初始化
	Motor_Init();		//直流电机初始化
	IR_Init();			//红外模块初始化
	Timer_Init();		//计时器初始化（红外遥控部分）
	
	//LED调试
	//LED_Init();
	
	/*显示静态字符串*/
	OLED_ShowString(1, 1, "Speed:");		//1行1列显示字符串Speed:
	
	while (1)
	{

		//红外遥控部分
			if(IR_GetDataFlag()==1)
		{
			//OLED_ShowNum(2,1,Data,8);
			
			switch (Data)
			{
				case NUM_0:ModeFlag=0;break;
				case NUM_1:ModeFlag=1;break;
				case NUM_2:ModeFlag=2;break;
				case NUM_3:ModeFlag=3;break;
				case NUM_4:ModeFlag=4;break;

			}
			switch(ModeFlag)
			{
				case 0:OLED_ShowString(2,1,"OFF          ");break;
				case 1:OLED_ShowString(2,1,"Low Speed    ");break;
				case 2:OLED_ShowString(2,1,"Medium Speed");break;
				case 3:OLED_ShowString(2,1,"High Speed    ");break;
				case 4:OLED_ShowString(2,1,"Max Speed      ");break;
			}
			OLED_ShowNum(3,1,ModeFlag,1);
		}
		
		
		switch(ModeFlag)
		{
			case 0:Speed=0;break;
			case 1:Speed=20;break;
			case 2:Speed=40;break;
			case 3:Speed=60;break;
			case 4:Speed=70;break;

		}

		Motor_SetSpeed(Speed);				//设置直流电机的速度为速度变量
		//OLED_ShowSignedNum(1, 7, Speed, 3);	//OLED显示速度变量
		

	}
}
